package com.bdcom.autotest.telnet;

import com.bdcom.autotest.telnet.invoke.DeveiceOper;
import com.bdcom.autotest.telnet.invoke.impl.*;
import com.bdcom.autotest.telnet.model.*;

import java.util.Properties;

public class Test {
    public static void main(String[] args)  {
        // TelnetExecuteCMD telnetExecuteCMD=new TelnetExecuteCMD("192.168.40.139",1,"admin","admin","admin","show version");
        //Properties pro=telnetExecuteCMD.executeResult();
        //System.out.println(pro);
       /* try {
            TelnetCommunication communication=new TelnetCommunication();
            TelnetClientForCOM clientForCOM=new TelnetClientForCOM("192.168.40.139",1);
            Result result=communication.login("admin","admin",clientForCOM);
            if(result.status){
                result=communication.enableOper(clientForCOM,"admin");
                System.out.println(result.getStatus());
            }else{
                System.out.println("false"+result.getFailedReason());
            }

        }catch (Exception e){
               e.printStackTrace();
        }*/

         //1.版本信息获取测试
        TelnetCMDObj obj=new TelnetCMDObj();
        obj.setIp("192.168.40.119");
        obj.setPort(23);
        obj.setUser("admin");
        obj.setPassword("admin");
        obj.setEnablePassword("admin");
        obj.setMonitor(false);
        DevVerInfo verInfo=new DevVerInfo();
        Result result = verInfo.obtainVerInfo(obj);
        if(result.getStatus()){
            System.out.println(result.getRetMsg());
        }else{
            System.out.println(false);
        }
        //2.主版本升级测试
       /* UpgradeMasterObj masterObj=new UpgradeMasterObj();
        masterObj.setIp("192.168.40.139");
        masterObj.setPort(1);
        masterObj.setUser("admin");
        masterObj.setPassword("admin");
        masterObj.setEnablePassword("admin");
        masterObj.setMonitor(true);
        masterObj.setDstFile("switch.bin");
        masterObj.setSrcFile("switch1.bin");
        masterObj.setTftpIP("192.168.40.196");
        DevUpgradeMaster upgradeMaster=new DevUpgradeMaster();
        Result upgradeResult = upgradeMaster.upgrade(masterObj);
        if(upgradeResult.getStatus()){
            System.out.println("upgrade master succeed!");
        }else{
            System.out.println("upgrade master failed!"+upgradeResult.getFailedReason());
        }*/

        //3.默认配置文件升级测试
        /*UpgradeDefaultConfigObj defaultConfigObj=new UpgradeDefaultConfigObj();
        defaultConfigObj.setIp("192.168.40.139");
        defaultConfigObj.setPort(1);
        defaultConfigObj.setUser("admin");
        defaultConfigObj.setPassword("admin");
        defaultConfigObj.setEnablePassword("admin");
        defaultConfigObj.setSrcFile("sshd_config");
        defaultConfigObj.setTftpIP("192.168.40.196");
        DevUpgradeDefaultConfig defaultConfig=new DevUpgradeDefaultConfig();
        Result defaultUpgradeResult = defaultConfig.upgrade(defaultConfigObj);
        if(defaultUpgradeResult.getStatus()){
            System.out.println("upgrade default-config succeed!");
        }else{
            System.out.println("upgrade default-config failed!"+defaultUpgradeResult.getFailedReason());
        }*/

        //4.formatReboot

        /*TelnetCMDObj obj=new TelnetCMDObj();
        obj.setIp("192.168.40.139");
        obj.setPort(2);
        obj.setUser("admin");
        obj.setPassword("admin");
        obj.setEnablePassword("admin");

        DevMonitor monitor=new DevMonitor();
        Result result = monitor.switchMonitor(obj);
        if(result.getStatus()){
            System.out.println("succeed into monitor");
        }else{
            System.out.println(false+result.getFailedReason());
        }*/

        //5.IP设置
        /*DevIPObj obj=new DevIPObj();
        obj.setIp("192.168.40.139");
        obj.setPort(2);
        obj.setUser("admin");
        obj.setPassword("admin");
        obj.setEnablePassword("admin");
        //设置的ip和mask
        obj.setIpAdd("192.168.40.179");
        obj.setMask("255.255.255.0");
        obj.setWantPingIP("192.168.40.196");
        DevIPSet ipSet=new DevIPSet();
        Result result = ipSet.setIPMask(obj);
        if(result.getStatus()){
            System.out.println("succeed set ip and mask");
            System.out.println(result.getRetMsg());
        }else{
            System.out.println("failed set ip and mask "+result.getFailedReason());
        }*/
        //6.MAC设置
        /*DevMACObj obj=new DevMACObj();
        obj.setIp("192.168.40.139");
        obj.setPort(1);
        obj.setUser("admin");
        obj.setPassword("admin");
        obj.setEnablePassword("admin");
        //设置MAC
        obj.setMac("00:55:b1:3f:82:88");
        DevMACSet macSet=new DevMACSet();
        Result result = macSet.setMAC(obj);
        if(result.getStatus()){
            System.out.println("succeed set mac");
        }else{
            System.out.println("failed set mac "+result.getFailedReason());
        }*/
        //7.重启
        /*TelnetCMDObj obj=new TelnetCMDObj();
        //obj.setMonitor(false);//主程序下重启
        obj.setMonitor(true);//monitor下重启
        obj.setIp("192.168.40.139");
        obj.setPort(1);
        obj.setUser("admin");
        obj.setPassword("admin");
        obj.setEnablePassword("admin");

        DevReboot reboot=new DevReboot();
        Result result = reboot.reboot(obj);
        if(result.getStatus()){
            System.out.println("succeed reboot,into "+result.getRetMsg());
        }else{
            System.out.println("failed reboot,"+result.getFailedReason());
        }*/
        //8.Telnet tunnel通道测试，通道内可以多次执行接口。流程是：1.开启tunnel；2执行接口（可执行多个）;3.关闭Tunnel
       /* TelnetTunnel tunnel=null;
        try {
            tunnel=new TelnetTunnel("192.168.40.139",1,"admin","admin","admin",true);
            //1.开启tunnel
            Result result=tunnel.startTunnel();
            if(result.getStatus()){
                //2.执行接口
                 //2.1 设置ip
                result=tunnel.setIPMask("192.168.40.179","255.255.255.0");
                if(result.getStatus()){
                    System.out.println("Set ip succeed!");
                    //2.2 升级主版本
                    result=tunnel.upgradeGen("BD_2228P_2.2.0D_92876_12034_2021.bin","Switch.bin","192.168.40.196");
                    if(result.getStatus()){
                        System.out.println("Upgrade succeed!");
                    }else{
                        System.out.println("Upgrade failed!"+result.getFailedReason());
                    }
                    //2.3升级默认的配置文件
                    result = tunnel.upgradeForDefaultConfig("default-config_12034_2021", "192.168.40.196");
                    if(result.getStatus()){
                        System.out.println("Upgrade Default-Config succeed!");
                    }else{
                        System.out.println("Upgrade Default-Config failed!"+result.getFailedReason());
                    }
                    //2.4升级eprom
                    result=tunnel.upgradeForEPROM("G20008053029bd.bin","192.168.40.196");
                    if(result.getStatus()){
                        System.out.println("Upgrade Eprom succeed!");
                    }else{
                        System.out.println("Upgrade Eprom failed!"+result.getFailedReason());
                    }
                }else{
                    System.out.println("Set ip failed!"+result.getFailedReason());
                }


            }else{
                System.out.println("Start tunnel failed!"+result.getFailedReason());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            //3.关闭tunnel
            tunnel.closeTunnel();
        }*/
        //9.当前通道判断
       /* try {
            TelnetClientForCOM clientForCOM=new TelnetClientForCOM("192.168.40.139",1);
            TelnetCommunication communication=new TelnetCommunication();
            System.out.println(communication.obtainCurrentPattern(clientForCOM));
        } catch (Exception e) {
            e.printStackTrace();
        }*/
       //10.eprom升级
      /*  UpgradeROMObj romObj=new UpgradeROMObj();
        romObj.setIp("192.168.40.139");
        romObj.setPort(1);
        romObj.setUser("admin");
        romObj.setPassword("admin");
        romObj.setEnablePassword("admin");
        romObj.setSrcFile("/FH20220406001-25/G20008053029bd.bin");
        romObj.setTftpIP("192.168.40.196");
        DevUpgradeROM upgradeROM=new DevUpgradeROM();
        Result upgradeResult = upgradeROM.upgradeROM(romObj);
        if(upgradeResult.getStatus()){
            System.out.println("upgrade ROM succeed!");
        }else{
            System.out.println("upgrade ROM failed!"+upgradeResult.getFailedReason());
        }*/



    }
}
